{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 波士顿房价预测案例——线性回归分析\n",
    "\n",
    "在这个案例中，我们将利用波士顿郊区的房屋信息数据训练和测试一个模型，并对模型的性能和预测能力进行测试。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1、导入必要的工具包"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np  # 矩阵操作\n",
    "import pandas as pd # SQL数据处理\n",
    "\n",
    "from sklearn.metrics import r2_score  #评价回归预测模型的性能\n",
    "\n",
    "import matplotlib.pyplot as plt   #画图\n",
    "import seaborn as sns\n",
    "\n",
    "# 图形出现在Notebook里而不是新窗口\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. 读取数据\n",
    "做完特征工程后的数据，请先运行2_FE_BostonHousePrice.ipynb，得到文件FE_boston_housing.csv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CRIM</th>\n",
       "      <th>ZN</th>\n",
       "      <th>INDUS</th>\n",
       "      <th>CHAS</th>\n",
       "      <th>NOX</th>\n",
       "      <th>RM</th>\n",
       "      <th>AGE</th>\n",
       "      <th>DIS</th>\n",
       "      <th>TAX</th>\n",
       "      <th>PTRATIO</th>\n",
       "      <th>...</th>\n",
       "      <th>RAD_2</th>\n",
       "      <th>RAD_3</th>\n",
       "      <th>RAD_4</th>\n",
       "      <th>RAD_5</th>\n",
       "      <th>RAD_6</th>\n",
       "      <th>RAD_7</th>\n",
       "      <th>RAD_8</th>\n",
       "      <th>RAD_24</th>\n",
       "      <th>MEDV</th>\n",
       "      <th>log_MEDV</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.18</td>\n",
       "      <td>0.067815</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.314815</td>\n",
       "      <td>0.577505</td>\n",
       "      <td>0.641607</td>\n",
       "      <td>0.269203</td>\n",
       "      <td>0.208015</td>\n",
       "      <td>0.3</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.422222</td>\n",
       "      <td>0.666856</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.000236</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.242302</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.172840</td>\n",
       "      <td>0.547998</td>\n",
       "      <td>0.782698</td>\n",
       "      <td>0.348962</td>\n",
       "      <td>0.104962</td>\n",
       "      <td>0.5</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.368889</td>\n",
       "      <td>0.619696</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.000236</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.242302</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.172840</td>\n",
       "      <td>0.694386</td>\n",
       "      <td>0.599382</td>\n",
       "      <td>0.348962</td>\n",
       "      <td>0.104962</td>\n",
       "      <td>0.5</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.660000</td>\n",
       "      <td>0.833335</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.000293</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.063050</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.150206</td>\n",
       "      <td>0.658555</td>\n",
       "      <td>0.441813</td>\n",
       "      <td>0.448545</td>\n",
       "      <td>0.066794</td>\n",
       "      <td>0.6</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.631111</td>\n",
       "      <td>0.816001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.000705</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.063050</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.150206</td>\n",
       "      <td>0.687105</td>\n",
       "      <td>0.528321</td>\n",
       "      <td>0.448545</td>\n",
       "      <td>0.066794</td>\n",
       "      <td>0.6</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.693333</td>\n",
       "      <td>0.852567</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 23 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       CRIM    ZN     INDUS  CHAS       NOX        RM       AGE       DIS  \\\n",
       "0  0.000000  0.18  0.067815   0.0  0.314815  0.577505  0.641607  0.269203   \n",
       "1  0.000236  0.00  0.242302   0.0  0.172840  0.547998  0.782698  0.348962   \n",
       "2  0.000236  0.00  0.242302   0.0  0.172840  0.694386  0.599382  0.348962   \n",
       "3  0.000293  0.00  0.063050   0.0  0.150206  0.658555  0.441813  0.448545   \n",
       "4  0.000705  0.00  0.063050   0.0  0.150206  0.687105  0.528321  0.448545   \n",
       "\n",
       "        TAX  PTRATIO  ...  RAD_2  RAD_3  RAD_4  RAD_5  RAD_6  RAD_7  RAD_8  \\\n",
       "0  0.208015      0.3  ...      0      0      0      0      0      0      0   \n",
       "1  0.104962      0.5  ...      1      0      0      0      0      0      0   \n",
       "2  0.104962      0.5  ...      1      0      0      0      0      0      0   \n",
       "3  0.066794      0.6  ...      0      1      0      0      0      0      0   \n",
       "4  0.066794      0.6  ...      0      1      0      0      0      0      0   \n",
       "\n",
       "   RAD_24      MEDV  log_MEDV  \n",
       "0       0  0.422222  0.666856  \n",
       "1       0  0.368889  0.619696  \n",
       "2       0  0.660000  0.833335  \n",
       "3       0  0.631111  0.816001  \n",
       "4       0  0.693333  0.852567  \n",
       "\n",
       "[5 rows x 23 columns]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# path to where the data lies\n",
    "#dpath = './data/'\n",
    "df = pd.read_csv(\"FE_boston_housing.csv\")\n",
    "\n",
    "#通过观察前5行，了解数据每列（特征）的概况\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "###  数据基本信息\n",
    "样本数目、特征维数\n",
    "每个特征的类型、空值样本的数目、数据类型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "#df.info()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 数据准备"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "# 从原始数据中分离输入特征x和输出y\n",
    "y = df[\"MEDV\"]\n",
    "\n",
    "X = df.drop([\"MEDV\", \"log_MEDV\"], axis = 1)\n",
    "\n",
    "#特征名称，用于后续显示权重系数对应的特征\n",
    "feat_names = X.columns"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "当数据量比较大时，可用train_test_split从训练集中分出一部分做校验集；\n",
    "样本数目较少时，建议用交叉验证。\n",
    "在线性回归中，留一交叉验证有简便计算方式。\n",
    "\n",
    "下面将训练数据分割成训练集和测试集，只是让大家对模型的训练误差、校验集上的测试误差估计、和测试集上的测试误差做个比较。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(404, 21)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#将数据分割训练数据与测试数据\n",
    "from sklearn.model_selection import train_test_split\n",
    "\n",
    "# 随机采样20%的数据构建测试样本，其余作为训练样本\n",
    "X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=33, test_size=0.2)\n",
    "X_train.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3、确定模型类型"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.1 尝试缺省参数的线性回归"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>columns</th>\n",
       "      <th>coef</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>RM</td>\n",
       "      <td>0.452377</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>ZN</td>\n",
       "      <td>0.129239</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>RAD_24</td>\n",
       "      <td>0.103221</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>B</td>\n",
       "      <td>0.078899</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>CHAS</td>\n",
       "      <td>0.059660</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>RAD_7</td>\n",
       "      <td>0.037664</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>RAD_8</td>\n",
       "      <td>0.030071</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>RAD_3</td>\n",
       "      <td>0.027465</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>INDUS</td>\n",
       "      <td>0.013818</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>AGE</td>\n",
       "      <td>-0.001228</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>RAD_4</td>\n",
       "      <td>-0.008698</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>RAD_5</td>\n",
       "      <td>-0.011517</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>RAD_2</td>\n",
       "      <td>-0.040970</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>RAD_6</td>\n",
       "      <td>-0.055736</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>RAD_1</td>\n",
       "      <td>-0.081501</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>TAX</td>\n",
       "      <td>-0.113548</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>NOX</td>\n",
       "      <td>-0.151553</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>PTRATIO</td>\n",
       "      <td>-0.187898</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>CRIM</td>\n",
       "      <td>-0.221874</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>DIS</td>\n",
       "      <td>-0.386249</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>LSTAT</td>\n",
       "      <td>-0.476675</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    columns      coef\n",
       "5        RM  0.452377\n",
       "1        ZN  0.129239\n",
       "20   RAD_24  0.103221\n",
       "10        B  0.078899\n",
       "3      CHAS  0.059660\n",
       "18    RAD_7  0.037664\n",
       "19    RAD_8  0.030071\n",
       "14    RAD_3  0.027465\n",
       "2     INDUS  0.013818\n",
       "6       AGE -0.001228\n",
       "15    RAD_4 -0.008698\n",
       "16    RAD_5 -0.011517\n",
       "13    RAD_2 -0.040970\n",
       "17    RAD_6 -0.055736\n",
       "12    RAD_1 -0.081501\n",
       "8       TAX -0.113548\n",
       "4       NOX -0.151553\n",
       "9   PTRATIO -0.187898\n",
       "0      CRIM -0.221874\n",
       "7       DIS -0.386249\n",
       "11    LSTAT -0.476675"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 线性回归\n",
    "#class sklearn.linear_model.LinearRegression(fit_intercept=True, normalize=False, copy_X=True, n_jobs=1)\n",
    "from sklearn.linear_model import LinearRegression\n",
    "\n",
    "# 1.使用默认配置初始化学习器实例\n",
    "lr = LinearRegression()\n",
    "\n",
    "# 2.用训练数据训练模型参数\n",
    "lr.fit(X_train, y_train)\n",
    "\n",
    "# 3. 用训练好的模型对测试集进行预测\n",
    "y_test_pred_lr = lr.predict(X_test)\n",
    "y_train_pred_lr = lr.predict(X_train)\n",
    "\n",
    "\n",
    "# 看看各特征的权重系数，系数的绝对值大小可视为该特征的重要性\n",
    "fs = pd.DataFrame({\"columns\":list(feat_names), \"coef\":list((lr.coef_.T))})\n",
    "fs.sort_values(by=['coef'],ascending=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 3.1.1 模型评价"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The r2 score of LinearRegression on test is 0.6939789810509471\n",
      "The r2 score of LinearRegression on train is  0.7549146436868177\n"
     ]
    }
   ],
   "source": [
    "# 使用r2_score评价模型在测试集和训练集上的性能，并输出评估结果\n",
    "#测试集\n",
    "print ('The r2 score of LinearRegression on test is', r2_score(y_test, y_test_pred_lr))\n",
    "#训练集\n",
    "print ('The r2 score of LinearRegression on train is ', r2_score(y_train, y_train_pred_lr))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAewAAAFsCAYAAAAOmoq4AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29md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j2lJalbPCUuSVIB7GFLklSAfv3CgT322CMnTpzYn7uUJGlAWbRo0TOZOaarz+vXwJ44cSILFy7sz11KkjSgRETdd/FrzVPikiQVwMCWJKkABrYkSQXo12vYkqT2bdiwgRUrVvDyy94ldbAYMWIEEyZMoKmpqVe2Z2BL0gCwYsUKdtllFyZOnEhEb31JmxolM1m7di0rVqxg0qRJvbJNT4lL0gDw8ssvs/vuuxvWg0REsPvuu/fqGRMDW5IGCMN6cOnt42lgS5JUAK9hS9IA1NLS/9sbNmwYhx56KBs3bmTSpEl897vfZbfdduvyvs477zw++tGPctBBB221/LrrrmPhwoVcc801Xd4mwMiRI1m3bl1d606bNo0rr7yS5ubmLcsWLlzIDTfcwNVXX92t/TeaPWxJEgCve93rWLx4MQ8//DCjR49mzpw53drON7/5zW3CeiBobm7u87DetGlTn23bwJYkbWPq1KmsXLlyy/wVV1zBkUceyWGHHcall14KwPr165kxYwaHH344hxxyCHPnzgVqvdvNt6H+zne+wwEHHMBxxx3HPffcs2V755xzDrfddtuW+ZEjRwKwbt06pk+fzhFHHMGhhx7K7bffvk1tq1at4thjj2Xy5Mkccsgh/PznP6+rTfPnz+fEE08EoKWlhXPPPZdp06ax3377bRXkN954I0cddRSTJ0/mgx/84JYQvvDCC2lububggw/e8hpA7bbbl112Ge985zu59dZb66qlOzwlLknayqZNm5g3bx6zZ88G4M4772Tp0qU88MADZCYnn3wyCxYsYM2aNey99978+Mc/BuC5557bajurVq3i0ksvZdGiRYwaNYp3vetdTJkyZbv7HjFiBD/4wQ/YddddeeaZZzj66KM5+eSTtxrA9b3vfY/jjz+ez3zmM2zatIkXX3yxW+38zW9+w1133cULL7zAW97yFi688EKWLVvG3Llzueeee2hqauKiiy7ipptu4uyzz+ZLX/oSo0ePZtOmTUyfPp2HHnqIww47bEvdd999d7fqqJeBLUkC4KWXXmLy5Mk8+eSTvO1tb+O9730vUAvsO++8c0vYrlu3jqVLl3LMMcfwsY99jE9+8pOceOKJHHPMMVtt7/7772fatGm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CwJUkqgIEtSVIBDGxJkgrw/wEmaznI8soIeQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 504x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#在训练集上观察预测残差的分布，看是否符合模型假设：噪声为0均值的高斯噪声\n",
    "f, ax = plt.subplots(figsize=(7, 5)) \n",
    "f.tight_layout() \n",
    "ax.hist(y_train - y_train_pred_lr, bins=40, label='Residuals Linear', color='b', alpha=.5); \n",
    "ax.set_title(\"Histogram of Residuals\") \n",
    "ax.legend(loc='best');"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "残差分布和高斯分布比较匹配，但还是大值这边的尾巴更长"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAARgAAADQCAYAAADcQn7hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAHotJREFUeJzt3Xl8VNX9//HXJzEJYQnIqqwpwhfZAkJAEBdA0IALQlFBQCKKRVFpXWoKbrQqVYpgi1IxuLCpFJAiqGxaFAGRsCQC0l9FsURkkU22rJ/fHzOxEbJMyNy5M5PP8/GYR2a5uef9CMmHe8899xxRVYwxxgkRbgcwxoQvKzDGGMdYgTHGOMYKjDHGMVZgjDGOsQJjjHGMFRhjjGOswBhjHGMFxhjjmPPcDlAWtWvX1vj4eLdjGFPhpaWlHVTVOqVtF1IFJj4+no0bN7odw5gKT0R2+7KdnSIZYxxjBcYY4xjXCoyIVBKRDSKyVUS2ich4t7IYY5zhZh9MFtBTVY+LSBSwRkQ+UNX1LmYyxviRa0cw6nHc+zLK+7DJaYxxQXZ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1cIyI1RKQynpntPiul2ZXAoIJTo0KnSL62Z1xgBcacq0fxnNKswjPXS4HRQDdvZ+x2YGQx378Gzzw9m4G3VHVLSY2pajrwPPCJd+a1iWVsz7jALlObgBORu4A2qvpbt7MYZ9kRjDHGMXYEY4xxjB3BGGMcYwXGGOMYKzDGGMdYgTHGOMYKjDHGMf8fRY5pgjODHioAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 288x216 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#还可以观察预测值与真值的散点图\n",
    "plt.figure(figsize=(4, 3))\n",
    "plt.scatter(y_train, y_train_pred_lr)\n",
    "plt.plot([-3, 3], [-3, 3], '--k')   #数据已经标准化，3倍标准差即可\n",
    "plt.axis('tight')\n",
    "plt.xlabel('True price')\n",
    "plt.ylabel('Predicted price')\n",
    "plt.tight_layout()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "在y的真值大的部分预测效果不好"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.2 正则化的线性回归（L2正则 --> 岭回归）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The r2 score of RidgeCV on test is 0.6961684813070188\n",
      "The r2 score of RidgeCV on train is 0.7548524440445546\n"
     ]
    }
   ],
   "source": [
    "#岭回归／L2正则\n",
    "#class sklearn.linear_model.RidgeCV(alphas=(0.1, 1.0, 10.0), fit_intercept=True, \n",
    "#                                  normalize=False, scoring=None, cv=None, gcv_mode=None, \n",
    "#                                  store_cv_values=False)\n",
    "from sklearn.linear_model import  RidgeCV\n",
    "\n",
    "#1. 设置超参数（正则参数）范围\n",
    "alphas = [ 0.01, 0.1, 1, 10,100]\n",
    "#n_alphas = 20\n",
    "#alphas = np.logspace(-5,2,n_alphas)\n",
    "\n",
    "#2. 生成一个RidgeCV实例\n",
    "ridge = RidgeCV(alphas=alphas, store_cv_values=True)  \n",
    "\n",
    "#3. 模型训练\n",
    "ridge.fit(X_train, y_train)    \n",
    "\n",
    "#4. 预测\n",
    "y_test_pred_ridge = ridge.predict(X_test)\n",
    "y_train_pred_ridge = ridge.predict(X_train)\n",
    "\n",
    "\n",
    "# 评估，使用r2_score评价模型在测试集和训练集上的性能\n",
    "print ('The r2 score of RidgeCV on test is', r2_score(y_test, y_test_pred_ridge))\n",
    "print ('The r2 score of RidgeCV on train is', r2_score(y_train, y_train_pred_ridge))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 可视化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZIAAAEKCAYAAAA4t9PUAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJzt3XmYHWWZ/vHvnTRJWIOEsGUhwQQhoGxtkEVlEQQcCEqQ4MhmNC4TZxzHGWEcFsH5KSPjgkEwGBTRkU3RBoKoJBESMaZDgNBZSCckpLOQDgkhC9mf3x9VDYfD6e7T6a4+p7vvz3Wdq6veeqvqqZPOefqpqlOvIgIzM7Nd1a3UAZiZWcfmRGJmZq3iRGJmZq3iRGJmZq3iRGJmZq3iRGJmZq3iRGJmZq3iRGJmZq3iRGJmZq1SUeoA2sP+++8fgwYNKnUYZmYdysyZM1dHRN/m+nWJRDJo0CCqq6tLHYaZWYciaUkx/Xxqy8zMWsWJxMzMWsWJxMzMWsWJxMzMWiXTRCLpHEnzJdVKurrA8p6S7kuXT5c0KG0/S9JMSbPTn2fkrHNp2v68pD9I2j/LYzAzs6Zllkg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/YGI2AmslDQ5Z52Dgfqc+U+mj/avSJcNI3msRa6dwH3p9C+B3AfwNUzPJEleALsB4yQdC+wADs/pv4rkUTVmmXIiMStOY4NMNTX41Bskz9BC0mDga8D7I2KtpJ83LGtG7jOMtqQ/d/DW/91/JXnG2TEkZxg25/TvlcZglimf2jIrzpPAJZK6p9ctPkTycMWpJAM/dZN0IMlwqw3mAkPS6X2AjcC6tN+5jeynG8nTfwE+lW6/Kb2BFWlFdBnJ8LkNDqc8nv5snZwrErPiPERy/eM5kirhPyJipaTfAGeSfGC/SDIy3bp0nUdJEsufI+I5SbNIng67CJjWyH42AkdJmplu55Jm4vox8BtJF5M8nXdjzrLT0xjMMuWn/5q1kqS9IhkVrw9JlXJKmmR2J/lwPyW9tlLMtjZExF5tFNeTwIiIWNsW2zNrjCsSs9Z7RNK+QA/gpohYCRARb0i6nmRs7JfbM6D09Nv3nESsPbgiMTOzVvHFdjMzaxUnEjMzaxUnEjMzaxUnEjMzaxUnEjMzaxUnEjMza5X/D3xJ7VD+ZB2hAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "alpha is: 0.1\n"
     ]
    }
   ],
   "source": [
    "mse_mean = np.mean(ridge.cv_values_, axis = 0)\n",
    "plt.plot(np.log10(alphas), mse_mean.reshape(len(alphas),1)) \n",
    "\n",
    "#这是为了标出最佳参数的位置，不是必须\n",
    "#plt.plot(np.log10(ridge.alpha_)*np.ones(3), [0.28, 0.29, 0.30])\n",
    "\n",
    "plt.xlabel('log(alpha)')\n",
    "plt.ylabel('mse')\n",
    "plt.show()\n",
    "\n",
    "print ('alpha is:', ridge.alpha_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>columns</th>\n",
       "      <th>coef_lr</th>\n",
       "      <th>coef_ridge</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>RM</td>\n",
       "      <td>0.452377</td>\n",
       "      <td>0.449104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>ZN</td>\n",
       "      <td>0.129239</td>\n",
       "      <td>0.125966</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>RAD_24</td>\n",
       "      <td>0.103221</td>\n",
       "      <td>0.099911</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>B</td>\n",
       "      <td>0.078899</td>\n",
       "      <td>0.079327</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>CHAS</td>\n",
       "      <td>0.059660</td>\n",
       "      <td>0.060075</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>RAD_7</td>\n",
       "      <td>0.037664</td>\n",
       "      <td>0.036712</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>RAD_8</td>\n",
       "      <td>0.030071</td>\n",
       "      <td>0.030423</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>RAD_3</td>\n",
       "      <td>0.027465</td>\n",
       "      <td>0.028356</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>INDUS</td>\n",
       "      <td>0.013818</td>\n",
       "      <td>0.011491</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>AGE</td>\n",
       "      <td>-0.001228</td>\n",
       "      <td>-0.001077</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>RAD_4</td>\n",
       "      <td>-0.008698</td>\n",
       "      <td>-0.008646</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>RAD_5</td>\n",
       "      <td>-0.011517</td>\n",
       "      <td>-0.011183</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>RAD_2</td>\n",
       "      <td>-0.040970</td>\n",
       "      <td>-0.039042</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>RAD_6</td>\n",
       "      <td>-0.055736</td>\n",
       "      <td>-0.055449</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>RAD_1</td>\n",
       "      <td>-0.081501</td>\n",
       "      <td>-0.081083</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>TAX</td>\n",
       "      <td>-0.113548</td>\n",
       "      <td>-0.110192</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>NOX</td>\n",
       "      <td>-0.151553</td>\n",
       "      <td>-0.145910</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>PTRATIO</td>\n",
       "      <td>-0.187898</td>\n",
       "      <td>-0.187369</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>CRIM</td>\n",
       "      <td>-0.221874</td>\n",
       "      <td>-0.212619</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>DIS</td>\n",
       "      <td>-0.386249</td>\n",
       "      <td>-0.374867</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>LSTAT</td>\n",
       "      <td>-0.476675</td>\n",
       "      <td>-0.474603</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    columns   coef_lr  coef_ridge\n",
       "5        RM  0.452377    0.449104\n",
       "1        ZN  0.129239    0.125966\n",
       "20   RAD_24  0.103221    0.099911\n",
       "10        B  0.078899    0.079327\n",
       "3      CHAS  0.059660    0.060075\n",
       "18    RAD_7  0.037664    0.036712\n",
       "19    RAD_8  0.030071    0.030423\n",
       "14    RAD_3  0.027465    0.028356\n",
       "2     INDUS  0.013818    0.011491\n",
       "6       AGE -0.001228   -0.001077\n",
       "15    RAD_4 -0.008698   -0.008646\n",
       "16    RAD_5 -0.011517   -0.011183\n",
       "13    RAD_2 -0.040970   -0.039042\n",
       "17    RAD_6 -0.055736   -0.055449\n",
       "12    RAD_1 -0.081501   -0.081083\n",
       "8       TAX -0.113548   -0.110192\n",
       "4       NOX -0.151553   -0.145910\n",
       "9   PTRATIO -0.187898   -0.187369\n",
       "0      CRIM -0.221874   -0.212619\n",
       "7       DIS -0.386249   -0.374867\n",
       "11    LSTAT -0.476675   -0.474603"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 看看各特征的权重系数，系数的绝对值大小可视为该特征的重要性\n",
    "fs = pd.DataFrame({\"columns\":list(feat_names), \"coef_lr\":list((lr.coef_.T)), \"coef_ridge\":list((ridge.coef_.T))})\n",
    "fs.sort_values(by=['coef_lr'],ascending=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.3 正则化的线性回归（L1正则 --> Lasso）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The r2 score of LassoCV on test is 0.6945099371682091\n",
      "The r2 score of LassoCV on train is 0.7548861511225584\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\Anaconda3\\lib\\site-packages\\sklearn\\model_selection\\_split.py:2053: FutureWarning: You should specify a value for 'cv' instead of relying on the default value. The default value will change from 3 to 5 in version 0.22.\n",
      "  warnings.warn(CV_WARNING, FutureWarning)\n"
     ]
    }
   ],
   "source": [
    "#### Lasso／L1正则\n",
    "# class sklearn.linear_model.LassoCV(eps=0.001, n_alphas=100, alphas=None, fit_intercept=True, \n",
    "#                                    normalize=False, precompute=’auto’, max_iter=1000, \n",
    "#                                    tol=0.0001, copy_X=True, cv=None, verbose=False, n_jobs=1,\n",
    "#                                    positive=False, random_state=None, selection=’cyclic’)\n",
    "from sklearn.linear_model import LassoCV\n",
    "\n",
    "#1. 设置超参数搜索范围\n",
    "#alphas = [ 0.01, 0.1, 1, 10,100]\n",
    "\n",
    "#2. 生成学习器实例\n",
    "#lasso = LassoCV(alphas=alphas)\n",
    "\n",
    "#1. 设置超参数搜索范围\n",
    "#Lasso可以自动确定最大的alpha，所以另一种设置alpha的方式是设置最小的alpha值（eps） 和 超参数的数目（n_alphas），\n",
    "#然后LassoCV对最小值和最大值之间在log域上均匀取值n_alphas个\n",
    "# np.logspace(np.log10(alpha_max * eps), np.log10(alpha_max),num=n_alphas)[::-1]\n",
    "\n",
    "#2 生成LassoCV实例（默认超参数搜索范围）\n",
    "lasso = LassoCV()  \n",
    "\n",
    "#3. 训练（内含CV）\n",
    "lasso.fit(X_train, y_train)  \n",
    "\n",
    "#4. 测试\n",
    "y_test_pred_lasso = lasso.predict(X_test)\n",
    "y_train_pred_lasso = lasso.predict(X_train)\n",
    "\n",
    "\n",
    "# 评估，使用r2_score评价模型在测试集和训练集上的性能\n",
    "print ('The r2 score of LassoCV on test is', r2_score(y_test, y_test_pred_lasso))\n",
    "print ('The r2 score of LassoCV on train is', r2_score(y_train, y_train_pred_lasso))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZIAAAEKCAYAAAA4t9PUAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJzt3Xt8XXWZ7/HPk3uTNkmbpLRJWtrSUmxLWzCgAqIjtzKDFBCkynEYZYZRD8fLjM7gcdSRmTlHxjnizMiMongZlEEGRYtcCgwColCaQkMvtCVNW5qml6RJ09xv+zl/7JWyG5Nmpzs7+5Lv+/Xar732Wr+19vNjQ76s22+ZuyMiInKqMhJdgIiIpDYFiYiIxERBIiIiMVGQiIhITBQkIiISEwWJiIjEREEiIiIxUZCIiEhMFCQiIhKTrEQXMBFKS0t93rx5iS5DRCSlbNy4scndy0ZrNymCZN68eVRXVye6DBGRlGJme6Npp0NbIiISEwWJiIjEREEiIiIxUZCIiEhMFCQiIhITBYmIiMREQSIiIjFRkIiIpKGafUf51jNv0NbdF/fvUpCIiKSh/3hxL99+ro7MDIv7dylIRETSzLHuPh7d3MDVK8vJz4n/ACYKEhGRNLN2UwPdfSHWnDdnQr5PQSIikmZ+umEfb5tdyNkVRRPyfQoSEZE0smV/K5v3t7LmvDmYxf/8CChIRETSyoPV+8jJyuCalRUT9p0KEhGRNNHdN8DDr+7nymWzKMrPnrDvVZCIiKSJJ7YcpK27nxsn6CT7IAWJiEiaeGrbIWYV5vHO+SUT+r0KEhGRNODuvFR3hAvOKCFjAm5CjKQgERFJA28cbudIRy/vPGNi90ZAQSIikhZe3HUEgHctUJCIiMgpeHHXESqKpzBnRv6Ef7eCREQkxYVCzvrdR3hXAg5rgYJERCTl7TjURktnX0IOa0Gcg8TMVpnZDjOrNbPbh1mea2Y/DZavN7N5Q5bPNbN2M/tctNsUEZlsBs+PJOJEO8QxSM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ftBM/sZcAnhP9g7gfVAa7DOo4SD5Wl3rzGzVwmPtFoH/HaE7+kAlprZxmA7N45S178BPzOzG4BfB+sP+oOgBpG40ui/IjEys6nu3m5mJYT3Ui4MQmYK4T/uFwbnVqLZVru7Tx2nup4HVnv4me8icaM9EpHY/crMioEc4O88eHCYu3eZ2VcIP9P7zYksKDj89g2FiEwE7ZGIiEhMdLJdRERioiAREZGYKEhERCQmChIREYmJgkRERGKiIBERkZj8f0dxKESE4EleAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "alpha is: 3.0853701706804334e-05\n"
     ]
    }
   ],
   "source": [
    "mses = np.mean(lasso.mse_path_, axis = 1)\n",
    "plt.plot(np.log10(lasso.alphas_), mses) \n",
    "#plt.plot(np.log10(lasso.alphas_)*np.ones(3), [0.3, 0.4, 1.0])\n",
    "plt.xlabel('log(alpha)')\n",
    "plt.ylabel('mse')\n",
    "plt.show()    \n",
    "            \n",
    "print ('alpha is:', lasso.alpha_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>columns</th>\n",
       "      <th>coef_lr</th>\n",
       "      <th>coef_ridge</th>\n",
       "      <th>coef_lasso</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>RM</td>\n",
       "      <td>0.452377</td>\n",
       "      <td>0.449104</td>\n",
       "      <td>0.452220</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>ZN</td>\n",
       "      <td>0.129239</td>\n",
       "      <td>0.125966</td>\n",
       "      <td>0.126455</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>RAD_24</td>\n",
       "      <td>0.103221</td>\n",
       "      <td>0.099911</td>\n",
       "      <td>0.107770</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>B</td>\n",
       "      <td>0.078899</td>\n",
       "      <td>0.079327</td>\n",
       "      <td>0.078393</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>CHAS</td>\n",
       "      <td>0.059660</td>\n",
       "      <td>0.060075</td>\n",
       "      <td>0.059860</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>RAD_7</td>\n",
       "      <td>0.037664</td>\n",
       "      <td>0.036712</td>\n",
       "      <td>0.044859</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>RAD_8</td>\n",
       "      <td>0.030071</td>\n",
       "      <td>0.030423</td>\n",
       "      <td>0.037731</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>RAD_3</td>\n",
       "      <td>0.027465</td>\n",
       "      <td>0.028356</td>\n",
       "      <td>0.036252</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>INDUS</td>\n",
       "      <td>0.013818</td>\n",
       "      <td>0.011491</td>\n",
       "      <td>0.009386</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>AGE</td>\n",
       "      <td>-0.001228</td>\n",
       "      <td>-0.001077</td>\n",
       "      <td>-0.000539</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>RAD_4</td>\n",
       "      <td>-0.008698</td>\n",
       "      <td>-0.008646</td>\n",
       "      <td>-0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>RAD_5</td>\n",
       "      <td>-0.011517</td>\n",
       "      <td>-0.011183</td>\n",
       "      <td>-0.002815</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>RAD_2</td>\n",
       "      <td>-0.040970</td>\n",
       "      <td>-0.039042</td>\n",
       "      <td>-0.030355</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>RAD_6</td>\n",
       "      <td>-0.055736</td>\n",
       "      <td>-0.055449</td>\n",
       "      <td>-0.046966</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>RAD_1</td>\n",
       "      <td>-0.081501</td>\n",
       "      <td>-0.081083</td>\n",
       "      <td>-0.071929</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>TAX</td>\n",
       "      <td>-0.113548</td>\n",
       "      <td>-0.110192</td>\n",
       "      <td>-0.108287</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>NOX</td>\n",
       "      <td>-0.151553</td>\n",
       "      <td>-0.145910</td>\n",
       "      <td>-0.147394</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>PTRATIO</td>\n",
       "      <td>-0.187898</td>\n",
       "      <td>-0.187369</td>\n",
       "      <td>-0.186683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>CRIM</td>\n",
       "      <td>-0.221874</td>\n",
       "      <td>-0.212619</td>\n",
       "      <td>-0.215736</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>DIS</td>\n",
       "      <td>-0.386249</td>\n",
       "      <td>-0.374867</td>\n",
       "      <td>-0.380508</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>LSTAT</td>\n",
       "      <td>-0.476675</td>\n",
       "      <td>-0.474603</td>\n",
       "      <td>-0.477194</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    columns   coef_lr  coef_ridge  coef_lasso\n",
       "5        RM  0.452377    0.449104    0.452220\n",
       "1        ZN  0.129239    0.125966    0.126455\n",
       "20   RAD_24  0.103221    0.099911    0.107770\n",
       "10        B  0.078899    0.079327    0.078393\n",
       "3      CHAS  0.059660    0.060075    0.059860\n",
       "18    RAD_7  0.037664    0.036712    0.044859\n",
       "19    RAD_8  0.030071    0.030423    0.037731\n",
       "14    RAD_3  0.027465    0.028356    0.036252\n",
       "2     INDUS  0.013818    0.011491    0.009386\n",
       "6       AGE -0.001228   -0.001077   -0.000539\n",
       "15    RAD_4 -0.008698   -0.008646   -0.000000\n",
       "16    RAD_5 -0.011517   -0.011183   -0.002815\n",
       "13    RAD_2 -0.040970   -0.039042   -0.030355\n",
       "17    RAD_6 -0.055736   -0.055449   -0.046966\n",
       "12    RAD_1 -0.081501   -0.081083   -0.071929\n",
       "8       TAX -0.113548   -0.110192   -0.108287\n",
       "4       NOX -0.151553   -0.145910   -0.147394\n",
       "9   PTRATIO -0.187898   -0.187369   -0.186683\n",
       "0      CRIM -0.221874   -0.212619   -0.215736\n",
       "7       DIS -0.386249   -0.374867   -0.380508\n",
       "11    LSTAT -0.476675   -0.474603   -0.477194"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 看看各特征的权重系数，系数的绝对值大小可视为该特征的重要性\n",
    "fs = pd.DataFrame({\"columns\":list(feat_names), \"coef_lr\":list((lr.coef_.T)), \"coef_ridge\":list((ridge.coef_.T)), \"coef_lasso\":list((lasso.coef_.T))})\n",
    "fs.sort_values(by=['coef_lr'],ascending=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
